﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Naruto.TaskManagement.Application;
using Naruto.TaskManagement.Entitys.DTO;
using Naruto.TaskManagement.Infrastructure;

namespace Naruto.TaskManagement.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly UserApps userApps;

        public UserController(UserApps _userApps)
        {
            userApps = _userApps;
        }
        /// <summary>
        /// 更新密码
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPut("updpswd/{userId}")]
        public async Task<NarutoResult> UpdatePassword(string userId, UpdatePasswordDTO info) => await userApps.UpdatePassword(userId, info);
        [AllowAnonymous]
        /// <summary>
        /// 注册
        /// </summary>
        /// <returns></returns>
        [HttpPost("register")]
        public async Task<NarutoResult> Register(RegisterDTO info) => await userApps.Register(info);
        [AllowAnonymous]
        /// <summary>
        /// 发送邮箱验证码
        /// </summary>
        /// <returns></returns>
        [HttpPost("code")]
        public async Task<NarutoResult> SendEmailCode(SendEmailCodeDTO info) => await userApps.SendEmailCode(info);
        [AllowAnonymous]
        /// <summary>
        /// 检查邮箱验证码
        /// </summary>
        /// <returns></returns>
        [HttpPost("code/check")]
        public async Task<NarutoResult> CheckCode(CheckCodeDTO info) => await userApps.CheckCode(info);
        [AllowAnonymous]
        /// <summary>
        /// 根据邮箱重置密码
        /// </summary>
        /// <returns></returns>
        [HttpPost("resetbyemail")]
        public async Task<NarutoResult> ResetPswdByEmail(ResetPswdByEmailDTO info) => await userApps.ResetPswdByEmail(info);
        /// <summary>
        /// 获取组织的用户信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route(template: "/api/organization/user")]
        public async Task<NarutoResult> GetOrganizationUser([FromQuery] GetOriginationUserDTO info) => await userApps.GetOriginationUser(info);


        [HttpPost("appointtomyorganization")]
        /// <summary>
        /// 邀请用户到我的组织
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public async Task<NarutoResult> AppointUserToMyOrganization(AppointUserToMyOrganizationDTO info) => await userApps.AppointUserToMyOrganization(info);

        /// <summary>
        /// 接受组织邀请
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("AcceptInvite/{id}")]
        public async Task<NarutoResult> AcceptInvite(string id) => await userApps.AcceptInvite(id);

        [HttpGet]
        [Route(template: "/api/organization/{id}/user")]
        /// <summary>
        /// 获取组织的用户信息
        /// </summary>
        /// <param name="id">组织id</param>
        /// <returns></returns>
        public async Task<NarutoResult> GetOrganizationUser(string id) => await userApps.GetOrganizationUser(id);

        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("base/{id}")]
        public async Task<NarutoResult> GetUserInfo(string id) => await userApps.GetUserInfo(id);

        [HttpGet("info/{id}")]
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        public async Task<NarutoResult> GetUserInfoBase(string id)=> await userApps.GetUserInfoBase(id);
    }
}
